package Com.javaserver.servlet;

import Com.javaserver.bean.departmentinquire;
import Com.javaserver.dao.departmentserver;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


//添加部门的接口
@WebServlet("/departA")
public class departmentserverlet extends HttpServlet {
    departmentserver departmentserver = new departmentserver();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String pname = req.getParameter("partname");
        String ptime = req.getParameter("parttime");
        String pnum = req.getParameter("partnum");
        String pnote = req.getParameter("partnote");

        departmentinquire deparad = new departmentinquire();
        deparad.setD_name(pname);
        deparad.setD_time(ptime);
        deparad.setD_number(pnum);
        deparad.setD_note(pnote);

        departmentserver depar=new departmentserver();


        if (departmentserver.departA(deparad) == null ) {
            req.getSession().setAttribute("msg", "添加失败");
            resp.sendRedirect(req.getContextPath() + "/Department.jsp");
        }
        else {
            List<departmentinquire> list = depar.queryALl(1);
            req.getSession().setAttribute("deptList", list);
            req.getSession().setAttribute("msg", "添加成功");
            resp.sendRedirect(req.getContextPath() + "/Department.jsp");
        }


    }

}

